<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户在线列表</title>
<link href="../css/manageadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="index.html">首页</a></li>
        <li>用户在线列表</li>
    </ul>
</div>
<div class="rightinfo">
    <table class="imgtable">
        <thead>
            <tr>
                <th><input id="selectAll" type="checkbox"/></th>
                <th>用户登录名</th>
                <th>用户真实姓名</th>
                <th>用户角色</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${applicationScope.ONLINE_USER}" var="usermap">
                <tr height="50px">
                    <td><input type="checkbox" name="userCheck" value="${usermap.key}"/></td>
                    <td>${usermap.value.userEmail}</td>
                    <td>${usermap.value.userRealname}</td>
                    <td>
                        <c:choose>
                            <c:when test="${usermap.value.userRole == 3}">普通用户</c:when>
                            <c:when test="${usermap.value.userRole == 2}">企业管理员</c:when>
                            <c:when test="${usermap.value.userRole == 1}">系统管理员</c:when>
                            <c:otherwise>未知角色</c:otherwise>
                        </c:choose>
                    </td>
                    <td>
                        <a href="ForceLogoutServlet?userId=${usermap.key}" class="tablelink">强制下线</a>
                    </td>
                </tr>
            </c:forEach>
            <c:if test="${empty applicationScope.ONLINE_USER}">
                <tr>
                    <td colspan="5" align="center">当前没有在线用户</td>
                </tr>
            </c:if>
        </tbody>
    </table>
</div>

<script>
    // 全选/取消全选功能
    document.getElementById('selectAll').addEventListener('change', function() {
        var checkboxes = document.querySelectorAll('input[name="userCheck"]');
        checkboxes.forEach(checkbox => {
            checkbox.checked = this.checked;
        });
    });
</script>
</body>
</html>
